<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <title>Cargo Administration</title>

    <link rel="stylesheet" type="text/css" th:href="@{/admin.css}"/>
</head>
<body>
<div th:replace="adminDecorator :: adminbody"/>
<div id="container">
    <table>
        <caption th:text="'Details for cargo ' + ${cargo.trackingId}"></caption>
        <tbody>
        <tr>
            <td>Origin</td>
            <td th:text="${cargo.origin}"></td>
        </tr>
        <tr>
            <td>Destination</td>
            <td th:text="${cargo.finalDestination}"></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <a th:href="@{/admin/pickNewDestination(trackingId=${cargo.trackingId})}">Change destination</a>
            </td>
        </tr>
        <tr>
            <td>Arrival deadline</td>
            <td th:text="${#dates.format(cargo.arrivalDeadline,'dd/MM/yyyy')}"/>
        </tr>
        </tbody>
    </table>
    <p></p>
    <th:block th:if="${cargo.routed}">
        <th:block th:if="${cargo.misrouted}">
            <p><em>Cargo is misrouted - <a th:href="@{/admin/selectItinerary(trackingId=${cargo.trackingId})}">reroute
                this cargo</a></em></p>
        </th:block>
        <table border="1">
            <caption>Itinerary</caption>
            <thead>
            <tr>
                <td>Voyage number</td>
                <td colspan="2">Load</td>
                <td colspan="2">Unload</td>
            </tr>
            </thead>
            <tbody>
            <tr th:each="leg : ${cargo.legs}">
                <td th:text="${leg.voyageNumber}"></td>
                <td th:text="${leg.from}"></td>
                <td th:text="${#dates.format(leg.loadTime,'dd/MM/yyyy')}"/>
                <td th:text="${leg.to}"></td>
                <td th:text="${#dates.format(leg.unloadTime,'dd/MM/yyyy')}"/>
            </tr>
            </tbody>
        </table>
    </th:block>
    <th:block th:if="${!cargo.routed}">
        <p>
            <strong>Not routed</strong> - <a th:href="@{/admin/selectItinerary(trackingId=${cargo.trackingId})}">Route this cargo</a>
        </p>
    </th:block>
</div>
</body>
</html>